package interview.huawei.training.p48;

import java.util.ArrayList;
import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        // 获取控制台参数
        // 链表结点个数
        int count = scanner.nextInt();
        // 头结点数据
        int headData = scanner.nextInt();
        ArrayList<Integer> list = new ArrayList<>();
        list.add(headData);
        for (int i = 0; i < count - 1; i++) {
            int node1 = scanner.nextInt();
            int node2 = scanner.nextInt();
            int index = list.indexOf(node2);
            list.add(index + 1, node1);
        }
        list.remove(list.indexOf(scanner.nextInt()));
        int i = 0;
        for (; i < list.size() - 1; i++) {
            System.out.print(list.get(i) + " ");
        }
        System.out.print(list.get(i));
    }
}